home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Readers / Gui4Cli / G4C / FSearch / FSearch.gc next >
Text File  |  1997-12-02  |  15KB  |  638 lines

  1. G4C
  2.  
  3. ; $VER: FSearch.gc 1.1 
  4. ; by D.Keletsekis 15/9/97
  5.  
  6. ; GUI for the FSearch command
  7.  
  8. ; You must have FSearch 1.1 in the guis:c/fsearch directory, or
  9. ; else change the paths given in the 2 Launch commands.
  10.  
  11. ; This gui can be called as :
  12. ; GUILOAD guis:g4c/fsearch.gc SearchPath
  13.  
  14. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  15. ;
  16. ;                            Globals
  17. ;
  18. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  19.  
  20. WINBIG 103 22 409 159 'FSearch 1.1 by D.Keletsekis'
  21. WinType 11110001
  22. varpath 'fsearch.ft/dir.gc'
  23. winout  "kcon:0/100/690/170/FSearch Output/auto/close/wait"
  24. BOX 2 13 406 128 OUT button
  25.  
  26.  
  27. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  28. ;
  29. ;                           System events
  30. ;
  31. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  32.  
  33. xOnLoad
  34. setgad FSearch.gc 101  hide
  35. setgad FSearch.gc 201/250 hide
  36. setgad FSearch.gc 300/350 hide
  37. setgad FSearch.gc 325/333 off   ; size
  38. setgad FSearch.gc 305/306 off   ; date
  39. GuiOpen FSearch.gc
  40. ; the default values
  41. if $$ARG.0 > ''
  42.    searchpath = $$ARG.0
  43. else
  44.    searchpath = sys:
  45. endif
  46. file = '#?'
  47. subdirs = ALL
  48. findtxt = ''
  49. case = ''
  50. strsearch = On
  51. output = gui
  52. format = 'VERBOSE'
  53. nobin = ''
  54. nopath = ''
  55. details = ''
  56. highlight = HL
  57. min_size = ''
  58. max_size = ''
  59. from = ''
  60. to = ''
  61. header = ''
  62. update fsearch.gc 2 $searchpath
  63. setgad fsearch.gc 7 on
  64. ; load the file types
  65. lvuse fsearch.ft 1
  66. lvchange :fsearch.types
  67.  
  68. xOnClose
  69. GuiQuit FSearch.gc
  70. GuiQuit fsearch.ft      ; filetypes gui
  71. GuiQuit fsearch.rmb
  72.  
  73. xONRMB
  74. if $guimode = RES
  75.    guiopen fsearch.rmb
  76. endif
  77.  
  78.  
  79. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  80. ;
  81. ;                          Gui Mode cycler
  82. ;
  83. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  84.  
  85. ; ---- a cycler to change the gui to its various modes
  86.  
  87. XCYCLER 2 0 186 13 "" guimode
  88. gadhelp 'Click to change the GUI mode'
  89. gadid 500
  90. gadkey m            ; use 'm' to cycle it
  91. CStr "FSearch Parameters"  PAR
  92. CStr "FSearch Settings" SET
  93. cstr "Date, Size & Type"  DATE
  94. cstr "FSearch Results" RES
  95. gosub FSearch.gc guichange
  96.  
  97. xroutine guichange
  98. docase $guimode
  99.   case = PAR
  100.        setgad FSearch.gc 1/13  show
  101.        setgad FSearch.gc 21/24 show
  102.        setgad FSearch.gc 101   hide
  103.        setgad FSearch.gc 300/350 hide
  104.        setgad FSearch.gc 201/250 hide
  105.        break
  106.   case = SET
  107.        setgad FSearch.gc 1/13  hide
  108.        setgad FSearch.gc 21/24 hide
  109.        setgad FSearch.gc 101   hide
  110.        setgad FSearch.gc 300/350 hide
  111.        setgad FSearch.gc 201/250 show
  112.        break
  113.   case = DATE
  114.        setgad FSearch.gc 1/13    hide
  115.        setgad FSearch.gc 21/24   hide
  116.        setgad FSearch.gc 101     hide
  117.        setgad FSearch.gc 201/250 hide
  118.        setgad FSearch.gc 300/350 show
  119.        break
  120.   case = RES
  121.        setgad FSearch.gc 1/13  hide
  122.        setgad FSearch.gc 21/24 hide
  123.        setgad FSearch.gc 101   show
  124.        setgad FSearch.gc 300/350 hide
  125.        setgad FSearch.gc 201/250 hide
  126.        break
  127. endcase
  128. ; redraw FSearch.gc
  129. ; NEW - using PARTREDRAW - looks great eh?
  130. partredraw FSearch.gc 4 15 402 124
  131.  
  132. if $guimode != RES
  133.     SetWintitle FSearch.gc 'FSearch by D. Keletsekis'
  134. endif
  135.  
  136.  
  137. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  138. ;
  139. ;                          Parameters
  140. ;
  141. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  142.  
  143. ; ------ choose searchpath(s)
  144.  
  145. BOX 10 20 388 64 in button
  146. gadid 12
  147.  
  148. CTEXT 20 25 "Search in :" #screen 8 2 0 0001
  149. gadid 1
  150.  
  151. XTEXTIN 18 37 350 13 "" searchpath sys: 100
  152. gadhelp 'This is the path FSearch will start searching from'
  153. gadid 2
  154. setgad FSearch.gc 5 on         ; set cursor to next textin gad
  155.  
  156. XBUTTON 370 37 18 13 "<"      ; choose a searchpath
  157. gadhelp 'Will pop-up a requester to let you choose a path'
  158. gadid 3
  159. ReqFile -1 -1 300 200 'Choose SearchPath:' DIR searchpath $searchpath
  160. update FSearch.gc 2 $searchpath
  161.  
  162. ; ---- filename pattern
  163.  
  164. CTEXT 21 54 "File name pattern :" #screen 8 2 0 0001
  165. gadid 4
  166.  
  167. XTEXTIN 17 65 371 13 "" file '#?' 100
  168. gadhelp 'Enter the filepattern wanted - #? means all files'
  169. gadid 5
  170. setgad FSearch.gc 7 on         ; set cursor to next textin gad
  171.  
  172. XCHECKBOX 364 24 25 9 "_Include sub-directories" subdirs ALL "" ON
  173. gadhelp 'Check ON to make FSearch recurse through all subdirectories'
  174. gadid 11
  175.  
  176. ; ---- text search
  177.  
  178. CTEXT 22 99 "Find text :" #screen 8 2 0 0001
  179. gadid 6
  180.  
  181. XTEXTIN 17 111 371 13 "" findtxt '' 100
  182. gadhelp 'Enter the text you want to find - or nothing for no text search.'
  183. gadid 7
  184.  
  185. BOX 9 92 389 37 IN BUTTON
  186. gadid 8
  187.  
  188. XCHECKBOX 360 97 25 9 "Case sensitive" case CS "" OFF
  189. gadhelp 'Check ON to make the search Case Sensitive'
  190. gadid 9
  191.  
  192.  
  193. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  194. ;
  195. ;                       Search results listview
  196. ;
  197. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  198.  
  199. XLISTVIEW 4 15 400 124 "" resfile "" 10 MULTI
  200. gadhelp "Display search results - Click RMB to save list contents"
  201. gadid 101
  202. gadfont #mono 8 001
  203.  
  204. ; deal with file - if running with dir.gc
  205. ifexists gui dir.gc
  206.    ; check the first characters
  207.  
  208.    ; use popup window to deal with choice, if it's a file
  209.  
  210.    if $resfile[0][4] = '›32m'
  211.        cutvar resfile[4] cut word  1 resfile
  212.        cutvar resfile cut char -4 temp   ; cut the csi
  213.        ifexists file $resfile
  214.            guiload guis:tools/rtn/FilePop \"$fsearch.gc/resfile\"
  215.        endif
  216.  
  217.    ; or it could be a file but with highlight off
  218.    
  219.    elseif $resfile[0][1] != ' '
  220.    and $resfile[0][1] != '›'
  221.        ifexists file $resfile
  222.            guiload guis:tools/rtn/FilePop \"$fsearch.gc/resfile\"
  223.        endif
  224.  
  225.    ; then it must be a line number.. I use CEd as an editor
  226.  
  227.    elseifexists port rexx_ced
  228.        cutvar resfile[4] cut word 1 resfile
  229.        sendrexx rexx_ced 'jump to line $resfile'
  230.    endif 
  231.  
  232. endif
  233.  
  234.  
  235.  
  236. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  237. ;
  238. ;                           FSearch settings
  239. ;
  240. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  241.  
  242. ; ------- output mode
  243.  
  244. BOX 23 28 175 71 in button
  245. gadid 201
  246.  
  247. XRADIO 156 38 18 9 output 2
  248. gadhelp 'Choose where you want the output from FSearch to go to'
  249. gadid 202
  250. rstr 'Output to Gui'   gui
  251. RStr 'Output to Shell' cli
  252.  
  253. ; ----------- Output format 
  254.  
  255. XRADIO 156 68 19 9 format 2
  256. gadhelp 'Says it all really..'
  257. gadid 203
  258. RStr  'Show text found' 'VERBOSE'
  259. RStr  'Filenames only'  ''
  260.  
  261. ; ------------ Settings - checkboxes
  262.  
  263. BOX 214 28 176 70 IN BUTTON
  264. gadid 208
  265.  
  266. XCHECKBOX 350 35 25 9 'Highlight results' highlight "HL" "" ON
  267. gadhelp 'Bask in the glory of colored ansi text - (OS V39)'
  268. gadid 205
  269.  
  270. XCHECKBOX 350 50 25 9 "Check binary files" nobin "" "NOBIN" ON
  271. gadhelp 'Check ON to make FSearch search binary files'
  272. gadid 211
  273.  
  274. XCHECKBOX 350 65 25 9 "Show File Path" nopath "" "NOPATH" ON
  275. gadhelp 'Will output filenames using their full path'
  276. gadid 212
  277.  
  278. XCHECKBOX 350 79 25 9 "Show File Details" details "INFO" "" OFF
  279. gadhelp 'Will also print out file size, date etc'
  280. gadid 213
  281.  
  282. ; ------- help & save settings
  283.  
  284. XBUTTON 299 119 91 13 "Help.."
  285. gadhelp 'Loads the FSearch.doc - the full Gui4Cli installation is needed'
  286. *FILENAME = '$$win.path\fsearch.readme'
  287. guiload guis:tools/read.gc
  288. guiopen read.gc
  289. gadid 220
  290.  
  291.  
  292.  
  293. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  294. ;
  295. ;                               DO IT!
  296. ;
  297. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  298.  
  299. ; This is where the commandline is formed and launched. The name of
  300. ; the variable which holds it is 'options'
  301.  
  302.  
  303. XBUTTON 20 143 91 13 "_Search"
  304. gadhelp 'Start the search!'
  305. gadid 501
  306. if $searchpath < ' '
  307.    setwintitle FSearch.gc 'Wrong parameters!'
  308.    stop
  309. endif
  310. SetWintitle FSearch.gc Searching...
  311.  
  312. ; --- construct the command line
  313.  
  314. options = '$searchpath '
  315. if $file != '#?'
  316. and $file > ' '
  317.     appvar options 'PAT=$file '
  318. endif
  319. if $findtxt > ' '
  320.     appvar options 'TXT=\"$findtxt\" $case '
  321. endif
  322. if $size = SIZE
  323.    if $min_size  > ' '
  324.    and $min_size > 0
  325.       min = $min_size
  326.       if $min_type = mb
  327.           min == $min * 1000
  328.       endif
  329.       appvar options 'MIN=$min '
  330.    endif
  331.    if $max_size  > ' '
  332.    and $max_size > 0
  333.       max = $max_size
  334.       if $max_type = mb
  335.           max == $max * 1000
  336.       endif
  337.       appvar options 'MAX=$max '
  338.    endif
  339.    if $min_size > $max_size
  340.    and $max_size != ''
  341.       ezreq 'Minimum size is more than\nMaximum size..' Ooops! ''
  342.       stop
  343.    endif
  344. endif
  345. if $date = DATED
  346.    if $from_date > ' '
  347.       appvar options 'FROM=$from_date '
  348.    endif
  349.    if $to_date > ' '
  350.       appvar options 'TO=$to_date '
  351.    endif
  352. endif
  353. extract header clean header
  354. if $header > ' '
  355. and $header != NONE
  356.    appvar options 'HEADER=$header'
  357.    appvar options '#? '
  358. endif
  359. appvar options '$format $nobin $nopath $details $highlight $subdirs'
  360.  
  361. ; disable gadgets
  362. setgad FSearch.gc 501/502 off
  363.  
  364. ; --- launch according to where it should output
  365.  
  366. if $output = cli
  367.       say '\n-------------- Search results :\n'
  368.       launch 1 'guis:c/FSearch $options'
  369.       say 'guis:c/FSearch $options\n'
  370. else
  371.       launch 2 'guis:c/FSearch >pipe:findres $options'
  372.       ; say 'guis:c/FSearch >pipe:findres $options\n'
  373.       update FSearch.gc 500 3        ; change gui to show results listview
  374.       guimode = RES
  375.       gosub FSearch.gc guichange
  376. endif
  377.  
  378. ; ---------- xONRETURN commands - handle returns according to launches
  379.  
  380. ; -- return from shell launch
  381.  
  382. xonreturn 1   ; to the shell
  383. say '-------------- Search finished.\n'
  384. setgad FSearch.gc 501/502 on
  385. SetWintitle FSearch.gc 'Search finished.'
  386.  
  387. ; -- return from gui output mode launch
  388.  
  389. xonreturn 2   ; to gui or file
  390. lvuse FSearch.gc 101
  391. setgad FSearch.gc 501/502 on
  392. SetWintitle FSearch.gc 'Search finished.'
  393.  
  394. ; -- the pipe event where the output is piped at
  395.  
  396. xpipe pipe:findres ON
  397. gadid 999
  398. lvuse FSearch.gc 101      ; whenever a line is available
  399. lvadd $$pipe              ; append it to our listv
  400.  
  401. ; -- We're all human..
  402.  
  403. xonfail
  404. setwintitle FSearch.gc '** Error **'
  405. setgad FSearch.gc 501/502 on
  406.  
  407.  
  408. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  409. ;
  410. ;                        Clear & cancel buttons
  411. ;
  412. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  413.  
  414. ; --------------- The CLEAR button - reset all settings
  415.  
  416. XBUTTON 205 143 91 13 "C_lear"
  417. gadhelp 'Clear the current gadgets - will not change hidden gadgets'
  418. gadid 502
  419. docase $guimode
  420.   case = PAR
  421.        file = #?
  422.        update FSearch.gc 5 $file
  423.        findtxt = ''
  424.        update FSearch.gc 7 ''
  425.        break
  426.   case = SET
  427.        break
  428.   case = DATE
  429.        date = ANY
  430.        update FSearch.gc 301 0
  431.        from_date = ''
  432.        update FSearch.gc 305 ''
  433.        to_date = ''
  434.        update FSearch.gc 306 ''
  435.        size = ANY
  436.        update FSearch.gc 321 0
  437.        min_size = ''
  438.        update FSearch.gc 325 ''
  439.        max_size = ''
  440.        update FSearch.gc 330 ''
  441.        min_type = kb
  442.        update FSearch.gc 329 0
  443.        max_type = kb
  444.        update FSearch.gc 333 0
  445.        setgad FSearch.gc 325/333 off   ; size
  446.        setgad FSearch.gc 305/306 off   ; date
  447.        header = NONE
  448.        update FSearch.gc 341 'All files'
  449.        break
  450.   case = RES
  451.        lvuse FSearch.gc 101   ; clear the lv
  452.        lvclear
  453.        break
  454. endcase
  455.  
  456. ; --------------- The CANCEL button
  457.  
  458. XBUTTON 300 143 91 13 "_Cancel"
  459. gadhelp 'Abort the Search!'
  460. gadid 503
  461. breaktask guis:c/FSearch C      ; break fsearch
  462. setgad FSearch.gc 999 CLEAN    ; stop & flush pipe output
  463. lvuse FSearch.gc 101
  464. lvadd "**** BREAK ****"
  465.  
  466.  
  467. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  468. ;
  469. ;                      SET DATE, SIZE & TYPE
  470. ;
  471. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  472.  
  473. ; The surrounding boxes
  474. BOX 13 17 381 47 in button
  475. gadid 335
  476. BOX 13 74 381 41 in button
  477. gadid 336
  478.  
  479. ; ----- Date
  480.  
  481. CTEXT 20 20 Date #screen 8 2 0 "0001"
  482. gadid 300
  483.  
  484. XRADIO 171 25 17 9 date 4
  485. gadid 301
  486. RStr 'Any date'    ANY
  487. RStr 'Files dated' DATED
  488. if $date = ANY
  489.    setgad FSearch.gc 305/306 off
  490. else
  491.    setgad FSearch.gc 305/306 on
  492. endif
  493.  
  494. XTEXTIN 298 31 77 12 "From:" from_date '' 100
  495. gadid 305
  496. setgad FSearch.gc 306 on
  497. XTEXTIN 298 45 77 12 "To:" to_date '' 100
  498. gadid 306
  499. setgad FSearch.gc 305 on
  500.  
  501. ; ----- Size
  502.  
  503. CTEXT 20 77 Size #screen 8 2 0 "0001"
  504. gadid 320
  505.  
  506. XRADIO 173 82 18 9 size 4
  507. gadid 321
  508. RStr 'Any size' ANY
  509. RStr 'Files sized' SIZE
  510. if $size = SIZE
  511.    setgad FSearch.gc 325/333 on
  512. else
  513.    setgad FSearch.gc 325/333 off
  514. endif
  515.  
  516. XTEXTIN 247 85 47 12 Over min_size "" 100
  517.   gadid 325
  518. XBUTTON 296 85 15 12 "<"
  519.   gadid 327
  520.   if $min_size > 0
  521.      counter min_size dec 1
  522.      update FSearch.gc 325 $min_size
  523.   endif
  524. XBUTTON 312 85 15 12 ">"
  525.   gadid 328
  526.   counter min_size inc 1
  527.   update FSearch.gc 325 $min_size
  528. XCYCLER 328 85 52 12 "" min_type
  529.   CStr Kb kb
  530.   CStr Mb mb
  531.   gadid 329
  532.  
  533. XTEXTIN 247 99 46 12 Under max_size "" 100
  534.   gadid 330
  535. XBUTTON 296 99 15 12 "<"
  536.   gadid 331
  537.   if $max_size > 0
  538.      counter max_size dec 1
  539.      update FSearch.gc 330 $max_size
  540.   endif
  541. XBUTTON 312 99 15 12 ">"
  542.   gadid 332
  543.   counter max_size inc 1
  544.   update FSearch.gc 330 $max_size
  545. XCYCLER 328 99 52 12 "" max_type
  546.   CStr Kb kb
  547.   CStr Mb mb
  548.   gadid 333
  549.  
  550. ; ----- File type
  551.  
  552. CTEXT 28 122 Type #screen 8 2 0 0001
  553. gadid 340
  554. TEXT 66 122 289 12 "All files" 80 BOX
  555. gadid 341
  556. XBUTTON 357 122 23 12 "<"
  557. gadid 342
  558. guiopen fsearch.ft
  559.  
  560. ; ##################################################################
  561. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  562. ;
  563. ;                            FSearch.ft
  564. ;
  565. ;         Gui with listview for choosing file header type
  566. ;
  567. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  568. ; ##################################################################
  569.  
  570. NEWFILE  fsearch.ft
  571.  
  572. WINBIG 245 109 179 116  ''
  573. WinType 00001000
  574. winonmouse 100 50
  575. varpath FSearch.gc
  576.  
  577. xoninactive
  578. guiclose fsearch.ft
  579.  
  580. xonrmb
  581. guiclose fsearch.ft
  582.  
  583. ; start off with empty listview - load the fsearch.types file in the
  584. ; fsearch.gc xonload event
  585.  
  586. XLISTVIEW 0 0 179 116  "" ftype '' 10 TXT
  587. gadid 1
  588. gadfont #mono 8 000
  589. guiclose fsearch.ft
  590. cutvar ftype cut word -1 header
  591. update FSearch.gc 341 $ftype
  592.  
  593.  
  594. ; ##################################################################
  595. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  596. ;
  597. ;                            FSearch.rmb
  598. ;
  599. ;         popup gui for RMB when in list results mode
  600. ;
  601. ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  602. ; ##################################################################
  603.  
  604. NEWFILE fsearch.rmb
  605.  
  606. WinBig 0 0 80 30 ""
  607. WinType 00001000
  608. winonmouse 30 6
  609.  
  610. xOnRMB
  611. guiclose fsearch.rmb
  612.  
  613. xOnInactive
  614. guiclose fsearch.rmb
  615.  
  616. ;=============================== Save files list
  617.  
  618. xbutton 0 0 0 15 "Save.." 
  619. gadhelp 'Save output as..'
  620. guiclose fsearch.rmb
  621. choice = ''
  622. ReqFile  -1 -1 300 200 "Save output as:" SAVE file $fsearch.gc/searchpath
  623. if $file > ' '
  624.    guiwindow fsearch.gc wait
  625.    lvuse fsearch.gc 101
  626.    lvsave $file
  627.    guiwindow fsearch.gc resume
  628. endif
  629.  
  630. ;=============================== copy files
  631.  
  632. xbutton 0 15 0 15 Cancel
  633. guiclose fsearch.rmb
  634.  
  635. ; should add copy/move/delete for files in the list..
  636.  
  637.  
  638.